package board.command;

import java.awt.*;

import sgf.SGFParseException;
import sgf.SGFUtils;

import board.Board;

/**
 * Represents a command that removes a stone from the Board.
 * @author TKington
 *
 */
public class RemoveCommand extends Command {
	/** The x,y location of the stone being removed. */
    private Point p;
    /** Stores the color that was removed for undo. */
    private int color;
    
    /**
     * Creates a RemoveCommand.
     * @param m the MoveCommand that will be reversed
     */
    public RemoveCommand(MoveCommand m) {
        p = new Point(m.getPoint());
        color = m.getPlayer();
    }
    
    @Override
	public boolean doIt(Board b) {
        b.remove(p.x, p.y);
        return true;
    }
    
    @Override
	public void undoIt(Board b) {
        b.setAt(p.x, p.y, color);
    }
    
    @Override
	public Rectangle getBounds() {
        return new Rectangle(p);
    }
    
    @Override
	public void validatePoints(int size) throws SGFParseException {
        SGFUtils.checkPoint(p, size);
    }
    
    /**
     * Returns the x,y location of the RemoveCommand.
     * @return the x,y location
     */
    public Point getPoint() { return p; }
}
